<?php

class BinhLuanController {

    public function invoke() {
        require_once LIBRARIES_ENTITIES_DATABASE;
        require_once LIBRARIES_ENTITIES_BINH_LUAN;
        $dir = dirname(__FILE__);
        $xtpl = new XTemplate($dir . DS . "view" . DS . "index.php");
        $HH_ID = 4;
        if (isset($_POST['hanghoa'])) {
            $HH_ID = $_POST['hanghoa'];
        }        
        $dsbinhluan = $this->layBinhLuan($HH_ID);
        if ($dsbinhluan != null) {
            echo "ksanfjk";
            foreach ($dsbinhluan as $value) {
                $xtpl->assign('TEN_NGUOI_DUNG', 'Nguyen Huu Phuoc');
                $xtpl->assign('NOI_DUNG_BINH_LUAN', $value->getBL_NOIDUNG());
                $xtpl->assign('NGAY_DANG', $value->getBL_NGAYDANG());
                 $xtpl->parse('main.binhluan.danhsach');
            }
           
            $xtpl->parse('main.binhluan');
            $xtpl->out('main');
        } else {
            echo "Chưa có bình luận nào";
        }
    }

    private function layBinhLuan($HH_ID) {
        $db = new Database();
        try {
            $binhluan = new M_Binh_luan();
            $binhluan->setHH_ID($HH_ID);
            $dsbinhluan = $binhluan->getListByHangHoa($db);
            return $dsbinhluan;
        } catch (Exception $exc) {
            echo $exc->getTraceAsString();
        }
    }

}
